<template>
  <div class="hydj_box">
    <header-comm></header-comm>
    <div class="header_sele" :style="$parent.$parent.collapsed==false?'left: 10%':'left:80px'">
      <div class="add_qy">
        <a-button type="primary" @click="adddj">添加等级</a-button>
      </div>
      <div>
        <div class="hydj" v-if="$store.state.tjwz">
          <hydjxg class="hydj_xgym"></hydjxg>
        </div>
        <div class="hydj" v-if="pricexg">
          <hypricexg class="hydj_xgym"></hypricexg>
        </div>
        <div class="seach">
       
        </div>
      </div>
    </div>
    <!-- 表格-================= -->
    <div class="bcg">
      <!-- <div class="hedlist">
        <div class="headbtn"></div>
      </div> -->
      <div class="glwz">
       
        <a-table
          @change="handleChangelist"
          :loading="loading"
          :columns="columns"
          :pagination="pagination"
          :dataSource="data"
        >
        
          <template slot="priceDiscount" slot-scope="text, record, index">
            <div class="bxred">{{text}}%</div>
          </template>
           <template slot="Icon" slot-scope="text, record, index">
            <div><img class="vipimg" :src="axios.defaults.baseURL+'/huiyuan/upload/LevelIcon/'+text "/></div>
          </template>
          <template slot="operation" slot-scope="text, record, index">
            <div class="editable-row-operations">
              <a class="del" @click="()=>xiugai(record,record.key)">修改</a>
              <a class="del" @click="()=>price(record,record.key)">价格权限</a>
              <a-popconfirm title="确定删除吗?" class="del" @confirm="() => onDelete(record,record.key)">
                <a href="javascript:;">删除</a>
              </a-popconfirm>
            </div>
          </template>
        </a-table>
        <div class="fot_z">注：注册用户会员等级为 “默认会员” 类型</div>
      </div>
    </div>
  </div>
</template>

<script>
import qs from "qs";
import headerComm from "../header-comm/header.vue";
import hydjxg from "./hydjxg.vue";
import hypricexg from "./hypricexg.vue";


const columns = [
  {
    title: "序号",
    dataIndex: "id_num"
  },
  {
    title: "图标",
    dataIndex: "Icon",
     scopedSlots: { customRender: "Icon" }
  },

  {
    title: "等级名称",
    dataIndex: "gradeName"
  },

  {
    title: "价格折扣",
    dataIndex: "priceDiscount",
    scopedSlots: { customRender: "priceDiscount" }
  },
  //  {
  //   title: "价格类型",
  //   dataIndex: "is_tax",
  //   scopedSlots: { customRender: "is_tax" }
  // },
  {
    title: "价格查看权限",
    dataIndex: "priceView"
  },
  {
    title: "默认等级",
    dataIndex: "defaultGrade"
  },
    {
    title: "允许寄售",
    dataIndex: "consign"
  },
  {
    title: "操作",
    dataIndex: "operation",
    scopedSlots: { customRender: "operation" }
  }
];

const data = [];
export default {
  data() {
    this.cacheData = data.map(item => ({ ...item }));
    return {
      data,
      pricexg:false,
      columns,
      pagination: {
        defaultPageSize: 10,
        showTotal: total => `共 ${total} 条数据`,
        total: 0
      },
      loading: true,
      selectedRowKeys: [],
      hydjlist: []
    };
  },
  components: {
    headerComm,
    hydjxg,
    hypricexg
  },
  methods: {
    //表格
    handleChangelist(pagination, khmc) {
      this.loading = false;
   
      this.axios
        .post(
          "huiyuan/memberLevelList.php",
          qs.stringify({
            page: pagination.current,
            pageSize: pagination.defaultPageSize,
            sqdwid: this.$store.state.bbl_sqdwid
          })
        )
        .then(res => {
        
          if (res.data.code == 303) {
            this.data = res.data.result.data;
            this.pagination.total = Number(res.data.result.total);
            this.loading = false;
            this.cacheData = this.data.map(item => ({
              ...item
            }));
            for (var i = 0; i < res.data.result.data.length; i++) {
              this.data[i].key = res.data.result.data[i].id_num;
             
             
            }
          } else {
            this.data = [];
          }
        });
    
    },

  

    xiugai(value, key) {
     
      this.hydjlist = value;
      this.$store.state.tjwz = true;
      this.$store.state.xiugaiflag = "123";

   
    },

      price(value, key) {
     
      this.hydjlist = value;
      this.pricexg = !this.pricexg;
      
   
    },
    //会员等级---删除
    onDelete(value, key) {
      const dataSource = [...this.data];
      this.data = dataSource.filter(item => item.key !== key);
      this.axios
        .post(
          "huiyuan/memberLevelDelete.php",
          qs.stringify({ id_num: value.id_num })
        )
        .then(res => {
        
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
          }
        });
    },
    adddj(value, key) {
      this.$store.state.tjwz = true;
      this.$store.state.xiugaiflag = "";
    },
   
  },
  computed: {
 
  },
  created() {
    this.handleChangelist(this.pagination);
   
  }
};
</script>

<style lang='less' scoped>
.hydj_box {
  // position: relative;

  .hydj {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999999999;
    height: 930px;
    .hydj_xgym {
      position: absolute;
      width: 80%;
      left: 50%;
      transform: translateX(-50%);
    }
  }
   .vipimg {
              width: 50px;
              height: 50px;
            }
  .header_sele {
    position: absolute;
    top: 55px;
    left: 200px;
    z-index: 999;
    text-align: right;
    width: 90%;
    background-color: #fff;
    box-shadow: 5px 5px 5px #ccc;
    // height: 50px;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .seach {
      display: inline-block;
      .sele {
        position: relative;
        i {
          position: absolute;
          top: 10px;
          right: 8px;
        }
      }
    }
    .list_head {
      display: inline-block;
      .tit {
        font-size: 16px;
      }
      padding: 10px 15px;
      .fl_right {
        .margin {
          margin: 0 5px;
        }
        .xzl_btn:hover {
          border: 0 !important;
          color: #fff !important;
          background: #1890ff !important;
        }
      }
    }
  }
  
  .glwz {
    width: 98%;
    position: absolute;
    top: 147px;
    left: 1%;
    background-color: #fff;
    border: 1px solid #ccc;
    .het {
      width: 100%;
      text-align: left;
      padding: 20px;
    }
    .ant-table-thead > tr,
    .ant-table-tbody > tr {
      height: 50px !important;
    }
    .del {
    }
  }

  .ant-spin-nested-loading > div > .ant-spin {
    top: 100px !important;
  }
  .del {
    padding-right: 15px;
    color: #40a9ff;
    cursor: pointer;
  }
  .fot_z {
    position: absolute;
    bottom: 20px;
    left: 26px;
    color: #999;
  }
}
</style>
